package com.weifly.weistock.core.event;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * 基于事件的服务
 *
 * @author weifly
 * @since 2019/8/8
 */
public abstract class AbstractEventService {

    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    /**
     * 增加股票事件监听器
     */
    protected void addStockEventListener(StockEventEnum stockEvent, PropertyChangeListener listener) {
        this.propertyChangeSupport.addPropertyChangeListener(stockEvent.getEvent(), listener);
    }

    /**
     * 触发股票事件
     */
    protected void fireStockEventChange(StockEventEnum stockEvent, Object oldValue, Object newValue) {
        this.propertyChangeSupport.firePropertyChange(stockEvent.getEvent(), oldValue, newValue);
    }
}
